package kr.hkit.androidcomplete01.ch17;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.MotionEvent;
import android.view.View;

public class StateView extends View {
	private Paint paint;
	private int ptx;
	private int pty;
	
	public StateView(Context context) {
		super(context);
		paint = new Paint(Paint.ANTI_ALIAS_FLAG);
	}

	@Override
	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);
		paint.setColor(Color.GREEN);
		canvas.drawCircle(ptx, pty, 16, paint);
	}
	
	public int getPtx() {
		return ptx;
	}

	public void setPtx(int ptx) {
		this.ptx = ptx;
	}

	public int getPty() {
		return pty;
	}

	public void setPty(int pty) {
		this.pty = pty;
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		super.onTouchEvent(event);
		if(event.getAction() == MotionEvent.ACTION_DOWN){
			ptx = (int)event.getX();
			pty = (int)event.getY();
			invalidate();
			return true;
		}
		return  true;
	}
}
